package main

import (
	"bytes"
	"fmt"
	"log"
	"github.com/valyala/fasthttp"
)

func main() {
	listenAddr := "127.0.0.1:8080"
	slash := []byte("/")
	requestHandler := func(ctx *fasthttp.RequestCtx) {
		uri := ctx.Request.RequestURI()
		ctx.Response.Header.SetContentType("application/json")
		switch {
		case bytes.Equal(uri, slash):
			fmt.Fprintf(ctx, "{\"message\":\"hello\"}")
		default:
			ctx.Response.SetStatusCode(404)
			fmt.Fprintf(ctx, "{\"message\":\"not found\"}")
		}

	}
	if err := fasthttp.ListenAndServe(listenAddr, requestHandler); err != nil {
		log.Fatalf("error in ListenAndServe: %s", err)
	}
}
